package org.ccpp.portal.utils;

import java.security.MessageDigest;

import sun.misc.BASE64Encoder;

public class UtilsFormato {

	public static String controlXSS(String texto){
		return texto.replaceAll("<", "&lt").replaceAll(">", "&gt");
	}
	
	public static long strToLong(String texto, long defecto){
		 try{
			 double d=Double.parseDouble(texto);
			 return (long)d;
		 }catch(Exception e2){
			 return defecto;
		 }
	}
	
	public static String cifrarSHA1(String valor) throws Exception{
		MessageDigest md = MessageDigest.getInstance("SHA");
		md.update(valor.getBytes("UTF-8")); 
		byte raw[] = md.digest(); 
		String hash = (new BASE64Encoder()).encode(raw); 
		return hash;
	}
	
}
